package com.kailong.servlet.admin;

import com.kailong.dao.ManageAdviceDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/admin/adminDeleteAdvice")
public class AdminDeleteAdvice extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String title = req.getParameter("title");
        int count = ManageAdviceDao.deleteAdvice(title);
        PrintWriter out = resp.getWriter();
        if (count >0){
            out.print("<script>");
            out.print("alert('删除成功！');");
            out.print("location.href='http://localhost:8080/Library/admin/adminAdviceSelectAll';");
            out.print("</script>");
        }else{
            out.print("<script>");
            out.print("alert('删除失败！');");
            out.print("location.href='http://localhost:8080/Library/admin/adminAdviceSelectAll';");
            out.print("</script>");
        }
    }
}
